package com.sugon.controller.device;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.DeviceLifeSpanRecordEntity;
import com.sugon.service.DeviceLifeSpanRecordService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 设备运行寿命记录Controller
 *
 * @author YuXD
 * @date 2022-09-05
 */
@Controller
@RequestMapping("devicelifespanrecord")
public class DeviceLifeSpanRecordController {
    @Autowired
    private DeviceLifeSpanRecordService deviceLifeSpanRecordService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<DeviceLifeSpanRecordEntity> deviceLifeSpanRecordList = deviceLifeSpanRecordService.queryList(query);
        int total = deviceLifeSpanRecordService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(deviceLifeSpanRecordList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        DeviceLifeSpanRecordEntity deviceLifeSpanRecord = deviceLifeSpanRecordService.queryObject(id);

        return R.ok().put("deviceLifeSpanRecord", deviceLifeSpanRecord);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ResponseBody
    public R save(@RequestBody DeviceLifeSpanRecordEntity deviceLifeSpanRecord) {
        deviceLifeSpanRecordService.save(deviceLifeSpanRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @AutoLog("设备运行寿命记录--修改")
    @RequestMapping("/update")
    @ResponseBody
    public R update(@RequestBody DeviceLifeSpanRecordEntity deviceLifeSpanRecord) {
        deviceLifeSpanRecordService.update(deviceLifeSpanRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @AutoLog("设备运行寿命记录--删除")
    @RequestMapping("/delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        deviceLifeSpanRecordService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<DeviceLifeSpanRecordEntity> list = deviceLifeSpanRecordService.queryList(params);

        return R.ok().put("list", list);
    }
}
